<template>
  <div class="dialog-warp" v-show="visible">
    <div class="dialog" :style="{ width: width + 'px' }">
      <div class="header">
        <span class="title">{{ title }}</span>
        <span class="close" @click="close">x</span>
      </div>
      <div class="main">
        <slot></slot>
      </div>
      <div>
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Dialog',
  props: {
    title: {
      type: String,
      dafault: '',
      require: true
    },
    visible: {
      type: Boolean,
      dafault: false
    },
    width: {
      default: 400
    }
  },
  data() {
    return {}
  },
  methods: {
    close() {
      // this.visible = false
      // console.log(1)
      this.$emit('handle-close')
    }
  },
  components: {}
}
</script>

<style scoped>
.close {
  cursor: pointer;
}
.dialog-warp {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: rgba(120, 121, 123, 0.5);
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dialog {
  width: 400px;
  min-height: 300px;
  background-color: #fff;
  box-shadow: 0 0 5px #ccc;
  flex-direction: column;
}
.dialog .header {
  display: flex;
  flex: 0 0 40px;
  border-bottom: 1px solid #ccc;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.main {
  display: flex;
  padding: 0 20px;
  box-sizing: border-box;
}
.footer {
  flex: 0 0 40px;
  padding: 0 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  border-top: 1px solid #ccc;
}
</style>
